using System;
using Habanero.Base;
using Habanero.BO;
using Habanero.BO.ClassDefinition;
using Habanero.Smooth;

namespace FireStarterModeller.Test.Logic
{
    public class MockBo : BusinessObject
    {

        public class InnerMockBo : MockBo
        {
            public new static ClassDef CreateClassDef()
            {
                return CreateClassDefWithProp<string>();
            }

            public new static ClassDef CreateClassDefWithProp<TPropType>()
            {
                return CreateMyClassDef<TPropType>(typeof(InnerMockBo));
            }
        }

        public static ClassDef CreateClassDef()
        {
            return CreateClassDefWithProp<string>();
        }

        public static ClassDef CreateClassDefWithProp<TPropType>()
        {
            return CreateMyClassDef<TPropType>(typeof(MockBo));
        }

        private static ClassDef CreateMyClassDef<TPropType>(Type classType)
        {
            PropDefCol propDefCol = new PropDefCol();
            PrimaryKeyDef primaryKeyDef = new PrimaryKeyDef();
            ClassDef classDef = new ClassDef(classType, primaryKeyDef,
                                             propDefCol, new KeyDefCol(), new RelationshipDefCol());
            PropDef idProp = new PropDef("IdProp", typeof(Guid), PropReadWriteRule.ReadWrite, null);
            propDefCol.Add(idProp);
            primaryKeyDef.Add(idProp);
            propDefCol.Add(new PropDef("TestProp", typeof(TPropType), PropReadWriteRule.ReadWrite, null));
            return classDef;
            
        }
        [AutoMapPrimaryKey]
        public Guid IdProp
        {
            get { return (Guid) GetPropertyValue("IdProp"); }
            set { SetPropertyValue("IdProp", value); }
        }

        public object TestProp
        {
            get { return GetPropertyValue("TestProp"); }
            set { SetPropertyValue("TestProp", value); }
        }
        public string TestStringProp
        {
            get { return (string) GetPropertyValue("TestStringProp"); }
            set { SetPropertyValue("TestStringProp", value); }
        }
    }
}
